﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="BatchModifyLowPriceControl.ascx.cs" 
    Inherits="Besture.UI.Admin.Control.BatchModifyLowPriceControl" %>
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
    <ContentTemplate>
        <table class="tablePrice">
            <tr>
                <th>酒店名称：</th>
                <td colspan="3" > 
                    <asp:DropDownList runat="server" ID="ddlUpdateHotels" />
                    <span id="RoomName"></span>
                </td>
            </tr>
            <tr>
                <th>适用星期：</th>
                <td>
                    <span id="chkWeekDayIndex">
                        <span class="base_label">
                            <input id="chkWeekDayIndex_0"  Data-Value="0" type="checkbox">
                            <label for="chkWeekDayIndex_0">全部</label>
                        </span>
                        <span class="base_label">
                            <input id="chkWeekDayIndex_1" type="checkbox" Data-Value="1" name="chkWeekDayIndex">
                            <label for="chkWeekDayIndex_1">周一</label>
                        </span>
                        <span class="base_label">
                            <input id="chkWeekDayIndex_2" type="checkbox" Data-Value="2" name="chkWeekDayIndex">
                            <label for="chkWeekDayIndex_2">周二</label>
                        </span>
                        <span class="base_label">
                            <input id="chkWeekDayIndex_3" type="checkbox" Data-Value="3" name="chkWeekDayIndex">
                            <label for="chkWeekDayIndex_3">周三</label>
                        </span>
                        <span class="base_label">
                            <input id="chkWeekDayIndex_4" type="checkbox" Data-Value="4" name="chkWeekDayIndex">
                            <label for="chkWeekDayIndex_4">周四</label>
                        </span>
                        <span class="base_label">
                            <input id="chkWeekDayIndex_5" type="checkbox" Data-Value="5" name="chkWeekDayIndex">
                            <label for="chkWeekDayIndex_5">周五</label>
                        </span>
                        <span class="base_label">
                            <input id="chkWeekDayIndex_6" type="checkbox" Data-Value="6" name="chkWeekDayIndex">
                            <label for="chkWeekDayIndex_6">周六</label>
                        </span>
                        <span class="base_label">
                            <input id="chkWeekDayIndex_7" type="checkbox" Data-Value="7" name="chkWeekDayIndex" >
                            <label for="chkWeekDayIndex_7">周日</label>
                        </span>
                    </span>
                </td>
            </tr>
            <tr> 
                <th>选择日期：
                </th>
                <td>  
                    <input type="text" class="Wdate" id="txtStartRoomTime" onFocus="WdatePicker({minDate:'%y-%M-{%d}',maxDate:'#F{$dp.$D(\'txtEndRoomTime\',{d:0});}'})"/>
                    至
                    <input   type="text" class="Wdate" id="txtEndRoomTime" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'txtStartRoomTime\',{d:0});}'})"/>
                </td>
                <td style="border-right: 1px solid #d6d6d6;" >
                    <asp:Button ID="btnSeach" runat="server" class="btn_blue"  Text="添加条目" OnClick="BtnSeachClick" />
                </td>
            </tr> 
        </table>
        <!--顶部操作按钮开始-->                          
        <div class="operateBar">
            <ul>
                <li><a href="javascript:grid.SelectRows();" class="operate-all"><s class="icon-gou-red"></s>全选</a></li>
                <li><a href="javascript:grid.UnselectRows();" class="operate-cancel"><s class="icon-cancel-yellow"></s>取消</a></li>
                <li><asp:LinkButton ID="lbAllDelete" runat="server" OnClientClick="return confirm('删除后无法恢复，确定删除选中项吗?');" class="operate-delete" OnClick="LbDelClick" ><s class="icon-delete"></s>删除</asp:LinkButton></li>
            </ul>
        </div> 
        <!--顶部操作按钮结束-->
        <cms:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" Width="100%"
            AutoGenerateColumns="False" KeyFieldName="ID" OnCustomCallback="GridCustomCallback"  >
            <Columns> 
                <cms:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="0" Width="50px" FixedStyle="Left" >
                    <HeaderTemplate>
                        <input type="checkbox" onclick="grid.SelectAllRowsOnPage(this.checked);" title="全选/全不选" id="chkAll" runat="server" />
                    </HeaderTemplate>
                    <HeaderStyle HorizontalAlign="Center" />
                </cms:GridViewCommandColumn> 
                <cms:GridViewDataTextColumn Caption="房型" VisibleIndex="1" Width="100px" HeaderStyle-HorizontalAlign="Center" CellStyle-HorizontalAlign="Left">
                    <DataItemTemplate>
                        <span tabindex="<%#Eval("RoomID").ToString() %>" ><%# GetRoomNameById(Eval("RoomID").ToString()) %></span>
                    </DataItemTemplate>
                </cms:GridViewDataTextColumn>
                <cms:GridViewDataDateColumn Caption="日期" VisibleIndex="2" Width="" HeaderStyle-HorizontalAlign="Center" CellStyle-HorizontalAlign="Left">
                    <DataItemTemplate>
                        <span tabindex="<%#Eval("RoomTime").ToString() %>" ><%#Eval("RoomTime") %></span>
                    </DataItemTemplate>
                </cms:GridViewDataDateColumn>  
                <cms:GridViewDataDateColumn Caption="适用星期" VisibleIndex="2" Width="" HeaderStyle-HorizontalAlign="Center" CellStyle-HorizontalAlign="Left">
                    <DataItemTemplate>
                        <span  Data-Id="<%=hidApplicableWeek.Value %>" ><%=GetWeekTime(hidApplicableWeek.Value.TrimEnd(',')) %></span>
                    </DataItemTemplate>
                </cms:GridViewDataDateColumn>  
                <cms:GridViewDataDateColumn Caption="预付底价" VisibleIndex="2"  HeaderStyle-HorizontalAlign="Center" CellStyle-HorizontalAlign="Left">
                     <DataItemTemplate>
                        <asp:TextBox ID="txtPrice" runat="server" class="required number" Text='<%#Eval("LowPrice") %>' style="width: 50px" ></asp:TextBox>
                    </DataItemTemplate>
                </cms:GridViewDataDateColumn>  
                <cms:GridViewDataTextColumn Caption="早餐情况" VisibleIndex="3" Name="Breakfast"  Width="100px" HeaderStyle-HorizontalAlign="Center" CellStyle-HorizontalAlign="Left">
                    <DataItemTemplate> 
                        <%# GetStringBreakfast() %>
                    </DataItemTemplate>
                </cms:GridViewDataTextColumn>
            </Columns>
        </cms:ASPxGridView> 
        <div style="text-align: center;margin-top: 15px;">
            <asp:Button runat="server" ID="Button1" CssClass="btn-sure btn-edit" Text="保存" OnClick="BtnSubmitClick" OnClientClick="return myValidate();" />
        </div>   
        <input type="hidden" id="hidRoomID" runat="server" />
        <input type="hidden" id="hidID" runat="server" value="0" />
        <input type="hidden" id="hidStartRoomTime" runat="server" value="0" />
        <input type="hidden" id="hidEndRoomTime" runat="server" value="0" />
        <input type="hidden" id="hidPrice" runat="server" value="0" />
        <input type="hidden" id="hidApplicableWeek" runat="server" value="0" />
    <%-- ReSharper disable once JumpMustBeInLoop --%>
        <script>
            function getUpdateHotels() {
                $("#<%=ddlUpdateHotels.ClientID%>").change(function () {
                    $.ajax({
                        type: "GET",
                        url: "/Admin/RoomPrice/AJaxPrice.aspx",
                        data: {
                            Hotels: $("#<%=ddlUpdateHotels.ClientID%>").val()
                        },
                        success: function (data) {
                            if (data.length > 0) {
                                $("#RoomName").html(data.toString());
                            }
                        }
                    });
                });
            }

            function getBtnBlue() {

                $(".dxgvFilterRow_DevExOABlue").css("display", "none");

                //点击【添加条目】 触发事件 
                $(".btn_blue").click(function() {
                    var roomId = '';
                    $("#RoomName input:checked").each(function () {
                        roomId += $(this).val() + ",";
                    });
                    if (roomId.length < 1) {
                        alert("请选择房型");
                        return false;
                    } else if ($("#txtStartRoomTime").val().length < 1 || $("#txtEndRoomTime").val().length < 1) {
                        alert("请选择日期");
                        return false;
                    } else {
                        $("#<%=hidRoomID.ClientID%>").val(roomId); //获取 房型id
                        $("#<%=hidID.ClientID%>").val(1); //标示字段
                        $("#<%=grid.ClientID%>").find("input").remove(); //处理input 校验

                        $("#<%=hidStartRoomTime.ClientID%>").val($("#txtStartRoomTime").val());
                        $("#<%=hidEndRoomTime.ClientID%>").val($("#txtEndRoomTime").val());

                    }
                });
            }


            function GetWeekId() {
                var vDWeek = "";
                if ($("#chkWeekDayIndex_0").attr("checked")) {
                    vDWeek += $("#chkWeekDayIndex_0").attr("Data-Value") + ","; //获取值
                } else {
                    $("#chkWeekDayIndex input:checked").each(function () {
                        vDWeek += $(this).attr("Data-Value") + ","; //获取值
                    });
                }
                $("#<%=hidApplicableWeek.ClientID%>").val(vDWeek);
            }

            function myValidate() {
                var arr = new Array();
                var vWeek = "";
                $(".dxgvTable_DevExOABlue").find(".dxgvDataRow_DevExOABlue").each(function (i) {
                    vWeek = $(this).find("#ctl00_Content_BatchModifyLowPriceControl_grid_tccell" + i + "_3").find("span").attr("Data-Id"); //周期

                    arr[i] = $(this).find("#ctl00_Content_BatchModifyLowPriceControl_grid_tccell" + i + "_1").find("span").attr("tabindex"); //房型ID
                    arr[i] += "," + $(this).find("#ctl00_Content_BatchModifyLowPriceControl_grid_tccell" + i + "_4").find("input").val();//预付底价   
                    arr[i] += "," + $(this).find("#ctl00_Content_BatchModifyLowPriceControl_grid_tccell" + i + "_5").find("select").val();//早餐情况
                    arr[i] += "|";
                }); 
                $("#<%=hidApplicableWeek.ClientID %>").val(vWeek);
                $("#<%=hidPrice.ClientID %>").val(arr);

                $(".pop-box input").addClass("ignore");
                return $("form").valid();
            }

          

            function GetChecked() {

                //初始化全选
                $("#chkWeekDayIndex input").each(function () {
                    $(this).attr("checked", true);
                });
                $("#<%=hidApplicableWeek.ClientID%>").val(0);


                $("#<%=btnSeach.ClientID %>").click(function () {
                    GetWeekId();
                });
                 
                var i = 1;
                $("#chkWeekDayIndex input[name='chkWeekDayIndex']").click(function () {
                    if ($(this).attr("checked")) {
                        i++;
                        if (i > 7) {
                            $("#chkWeekDayIndex_0").attr("checked", true);
                            i = 1;
                        }
                    } else {
                        $("#chkWeekDayIndex_0").attr("checked", false);
                        i--;
                    }
                });

                $("#chkWeekDayIndex_0").click(function () {
                    var vDWeek = "";
                    if ($(this).attr("checked")) {
                        $("#chkWeekDayIndex input").each(function () {
                            $(this).attr("checked", true);
                        });
                    } else {
                        $("#chkWeekDayIndex input").each(function () {
                            $(this).attr("checked", false);
                        });
                    }
                });

            }

            $(function () { 
                GetChecked();  //适用星期 js
                getUpdateHotels();//酒店名称控件 初始化 下拉框
                getBtnBlue();//【添加条目】 初始化 触发事件
            });

        </script>
    </ContentTemplate>
   <Triggers>
    <asp:PostBackTrigger ControlID="Button1" />
    </Triggers>
</asp:UpdatePanel>
 
 